package com.shouer.doc;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;

import io.rong.push.notification.PushMessageReceiver;
import io.rong.push.notification.PushNotificationMessage;

/**
 * Created by yangyayun on 2016/11/10.
 */

public class ShouerNotificationReceiver extends PushMessageReceiver {
    @Override
    public boolean onNotificationMessageArrived(Context context, PushNotificationMessage pushNotificationMessage) {
        Log.e(ShouerNotificationReceiver.class.getSimpleName(),"onNotificationMessageArrived");


        Log.e("getPushId():",pushNotificationMessage.getPushId());
        Log.e("getPushContent():",pushNotificationMessage.getPushContent());
        Log.e("getPushData():",pushNotificationMessage.getPushData());
        Log.e("getPushFlag():",pushNotificationMessage.getPushFlag());
        Log.e("getPushTitle():",pushNotificationMessage.getPushTitle());

        Log.e("getSenderId():",pushNotificationMessage.getSenderId());
        Log.e("getSenderName():",pushNotificationMessage.getSenderName());

        Log.e("getTargetId():",pushNotificationMessage.getTargetId());
        Log.e("getTargetUserName():",pushNotificationMessage.getTargetUserName());

        Log.e("getConversationType():",pushNotificationMessage.getConversationType().toString());

        Log.e("getExtra():",null==pushNotificationMessage.getExtra()?"Null":pushNotificationMessage.getExtra());
        Log.e("getObjectName():",pushNotificationMessage.getObjectName());
        //订单消推送
        if (pushNotificationMessage.getObjectName().equals("App:OrdMsg"))
        {
            NotificationInterface.sendNotification(context,pushNotificationMessage);
            return true;
        }else if (pushNotificationMessage.getObjectName().equals("App:txtMsg"))
        {
            NotificationInterface.sendAppTxtMsgNotification(context,pushNotificationMessage.getPushContent());
            return true;
        }

        return false;
    }

    @Override
    public boolean onNotificationMessageClicked(Context context, PushNotificationMessage pushNotificationMessage) {
        Log.e(ShouerNotificationReceiver.class.getSimpleName(),"onNotificationMessageArrived");
        if (pushNotificationMessage.getObjectName().equals("App:OrdMsg"))
        {
            Uri uri = Uri.parse("rong://" + context.getApplicationInfo().packageName).buildUpon().appendPath("neworder").build();
            Intent intent=new Intent("android.intent.action.VIEW", uri);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
            return true;
        }
        return false;
    }
}
